/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wangxin
 * Date: 2025-01-19
 * Time: 22:11
 */
public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode prev ;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode head;
    public ListNode last;
    public int usedSize;
  //从队尾入队列
    public void offer(int val) {
        ListNode node = new ListNode(val);
        if(head == null) {
            head = last = node;
        }else {
            last.next = node;
            node.prev = last;
            last = last.next;
        }
        usedSize++;
    }
    //从队头出队列，并将删除的元素返回
    public int poll() {
        if(head == null) {
            return -1;
        }
        int ret = head.val;
        if(head.next == null) {
            head = null;
            last = null;
        }else {
            head = head.next;
            head.prev = null;
        }
        usedSize--;
        return ret;
    }
    //获得队头元素
    public int peek() {
        if(head == null) {
            return -1;
        }
        return head.val;
    }
    //获取队列容量
    public int size(){
        return usedSize;
    }
   //判断是否为空
    public boolean isEmpty() {
        return head == null;
    }
}
